{include file="public/_header"}
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form toolbar">

            </form>
            <table id="tableContainer" lay-filter="tableContainer"></table>
        </div>
    </div>
</div>
{include file="public/_footer"}
<script>
    layui.use(['layer', 'form', 'admin', 'table'],function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;
        var table = layui.table;

        initTable();
        function initTable() {
            var url = '{:url("getData")}';
            var insTb = table.render({
                elem: '#tableContainer',
                url: url,
                toolbar: ['<p>',
                    '<button lay-event="add" class="layui-btn layui-btn-sm icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>&nbsp;',
                    '</p>'].join(''),
                cols: [[
                    {type: 'checkbox'},
                    {
                        field:'id',title:"ID",width:'5%'
                    },
                    {
                        field:'title',title:"标题",width:'10%',
                    },
                    {
                        field:'url',title:"跳转连接",width:'20%'
                    },
                    {
                        field:'sort',title:"排序",width:'5%',
                    },
                    {
                        field:'create_time', title:"创建时间",width:'15%'
                    },
                    {
                        fixed:'right', title:"操作", width: '40%', align:'center', toolbar: '#barDemo'
                    }
                    ]]
            });
        }

        table.on('tool(tableContainer)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                del(data.id);
            }else if(obj.event === 'edit') {
                window.location.href = "{:url('edit')}?id=" + data.id;
            }
        });

        table.on('toolbar(tableContainer)', function (obj) {
            if (obj.event === 'add') { // 添加
                window.location.href = "/auth/menu/add.html";
            }
        });

        function del(id) {
            var data = {
                id: id
            };
            layer.confirm('确定要删除吗？',{
                btn: ['确定', '取消']
            },function (e) {
                $.post("{:url('del')}",data,function (res) {
                    if(res.code === 0) {
                        layer.msg(res.msg);
                    }else {
                        layer.msg(res.msg);
                    }
                    window.location.reload();
                },'JSON');
            });
        }
    });
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
</body>
</html>